#pragma once

namespace stream {

class IOpenable{
public:
	virtual ~IOpenable(){}
	virtual bool open() {
		if(!_isOpened){
			bool ret = _open();
			if(ret){
				_isOpened = true;
			}
			return ret;
		}
		return false;
	}
	virtual void close() {
		if(_isOpened){
			_close();
			_isOpened = false;
		}
	}
	bool isOpened() const{
		return _isOpened;
	}
protected:
	virtual bool _open() = 0;
	virtual void _close() = 0;
private:
	bool _isOpened = false;
};

}//end namespace stream
